Xbasic

EVAL_KEYLENGTH Function

Syntax

Key_Length as N = EVAL_KEYLENGTH(Key_Expression as C [, eval_context as C])

Arguments

Key_ExpressionCharacter

The name of a field of a table.

eval_contextCharacter

Default = Primary table. Table_Name_List is a list of tables in a CR-LF delimited list. This parameter indicates what tables to open in order to evaluate the expression.

Returns

Key_LengthNumeric

Returns the length of the key specified by Key_Expression.

Description

Return the maximum length of the data an expression can return.

Discussion

EVAL_KEYLENGTH() returns the integer length of the key specified by Key_Expression.

Knowing the key length of an index or query key can be important because Alpha Anywhere only supports key lengths of 100 characters of less. If you use a key length of more than 100 characters, your data may not appear to sort correctly because Alpha Anywhere ignores key values past the first 100 characters.

EVAL_KEYLENGTH() differs from the LEN() function in that it always returns a length that is based on the defined size of a field. For example, assume that lastname is defined as a 20 character field. len(alltrim(LASTNAME)) would return 5, if LASTNAME contained "Smith", but eval_keylength("alltrim(LASTNAME)") always returns 20, regardless of the contents of the field.

Example

Assume you have a button on a form that executes this Xbasic. If the LASTNAME field is defined as 20 characters the message box will display 20, even though the length of the actual data in LASTNAME may be less.

lkey = eval_keylength("alltrim(employees->lastname)")
ui_msg_box("keylength",str(lkey))

See Also